const https = require('node:https');

const options = {
  port: '443',
  method: "GET",
  headers: {
    'content-type': 'application/json'
  }
};

let clientReq = function fb(api) {
  return new Promise((resolve, reject) => {
    const req = https.request(api, options, (res) => {
      let body = '';
      res.on('data', (chunk) => {
        body += chunk;
      });

      res.on('end', () => {
        if (body instanceof Array) {
          resolve(JSON.stringify(body));
        } else {
          resolve(body);
        }
      });

    });
    req.on('error', (e) => {
      console.error(e);
      reject(e);
    });
    req.end();
  });

};

module.exports = clientReq;